package com.hghivln.blog.shiro;



import com.hghivln.blog.entity.SysUser;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.apache.shiro.web.util.WebUtils;
import org.springframework.util.StringUtils;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.Serializable;
import java.util.UUID;

public class TokenWebSessionManager extends DefaultWebSessionManager {

    @Override
    protected Serializable getSessionId(ServletRequest request, ServletResponse response) {
        String token = WebUtils.toHttp(request).getHeader("Authorization");
        if (StringUtils.hasText(token)){
            return token;
        }
        // 访问数据量小时,可用UUID代替雪花算法生成id
        return UUID.randomUUID().toString();
    }

}
